<div id="ova-jwplayer-container"></div>
<div id="companion"></div>
<script type='text/javascript'>
var url = 'http://static.you2play.com/2013/assets/uploads/song/files/2013/09/25/3bbb163bc92d0acf1f8a4bd5f3838f7a.mp3';
var playlist = [{file:""+url+""}];
jwplayer('ova-jwplayer-container').setup({
  "autostart": true,
  "flashplayer": "<?php echo js_asset_url('media/player.swf');?>",
  "playlist": playlist,
  "width": 400,
  "height": 250,
  "controlbar": {
    "position": "bottom"
  },
  "plugins": {
/*    "<?php echo js_asset_url('media/ova-jw.swf');?>": {	*/	
    "ova-jw": {			
      "ads": {
        "skipAd": {
          "enabled": "true",
		  "closebuttontimeout": 5
        },
        "schedule": [
          {
            "position": "pre-roll",
            "tag": ""+generatTag()+""
          }	  
        ]
      }
    }
  }
/*  "plugins": {
    "ova-jw": {
      "ads": {
        "skipAd": {
          "enabled": "true"
        },
        "servers": [
          {
            "type": "OpenX",
            "apiAddress": "http://ads.you2play.com/openx/delivery/fc.php"
          }
        ],
        "companions": {
          "regions": [
            {
              "id": "companion",
              "width": 300,
              "height": 250
            }
          ]
        },
        "schedule": [
          {
            "position": "pre-roll",
            "zone": "163"
          },
          {
            "position": "pre-roll",
            "zone": "163"
          }		  
        ]
      },
      "debug": {
        "levels": "fatal, config, vast_template"
      }
    }
  }*/
});
jwplayer('ova-jwplayer-container').onComplete(function() {
	var config = { 
	"ads": {
        "skipAd": {
          "enabled": "true",
		  "closebuttontimeout": 5
        },
        "schedule": [
          {
            "position": "pre-roll",
            "tag": ""+generatTag()+""
          }	  
        ]
      }
	};
	jwplayer('ova-jwplayer-container').getPlugin('ova').scheduleAds(playlist, config);
});
function generatTag() {
	var Ads = [
	{
		name : "Zone 163",
		vast : "http://ads.you2play.com/openx/delivery/fc.php?script=bannerTypeHtml:vastInlineBannerTypeHtml:vastInlineHtml&source=&format=vast&charset=UTF_8&nz=1&zones=z1=163",
		weigth : 5
	},
	{
		name : "Azay",
		vast : "http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=7784956&PluID=0&pos=2708&ord=[timestamp]&cim=1",
		weigth : 3		
	},
	{
		name : "PTN",
		vast : "http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=7750794&PluID=0&pos=7104&ord=[timestamp]&cim=1",
		weigth : 2		
	},
	{
		name : "OP Relationship",
		vast : "http://rtb.tubemogul.com/--nt/vast2/78CyiOkhL09fjgMgXTl6/?duration=30&url=%5bpage_url%5d&vpaid=T",
		weigth : 1		
	},
	{
		name : "Mazda",
		vast : "http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=7893884&PluID=0&pos=2218&ord=[timestamp]&cim=1",
		weigth : 1		
	}
	];
	var Sequence = "";
	for(i=0;i<Ads.length;i++){
		for(j=0;j<Ads[i].weigth;j++){
			Sequence += ""+i+",";
		}
	}
	Sequence = Sequence.slice(0,-1);
	var Sequence_arr = Sequence.split(',');
	var indexAt = Sequence_arr[Math.floor(Math.random()*Sequence_arr.length)];
    return Ads[indexAt].vast;
}
</script>